var express = require('express');
var router = express.Router();
const theatersApi = require("../api/theaters");


/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('index', { title: 'Express' });
});

/**
 * @swagger
 * /theaters/getTheaters:
 *    get:
 *      tags:
 *      - 放映厅         # 接口分类
 *      summary: 放映厅查询接口   # 接口备注
 *      description: 放映厅查询接口   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      parameters:
 *        - in: query
 *          name: cinemasId
 *          schema:
 *            type: string
 *          description: 电影院ID
 *        - in: query
 *          name: curPage
 *          schema:
 *            type: string
 *            default: 1
 *          description: 当前页
 *        - in: query
 *          name: eachPage
 *          schema:
 *            type: string
 *            default: 3
 *          description: 每页显示条数
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "成功" #
 * */

router.get('/getTheaters', async function (req, res, next) {

    const { cinemasId, curPage, eachPage } = req.query;
    const data = await theatersApi.getTheaters({ cinemasId, curPage, eachPage });

    res.send(data)
});


/**,
 * @swagger
 * /theaters/delTheaters:
 *    delete:
 *      tags:
 *      - 放映厅          # 接口分类
 *      summary: 放映厅删除接口   # 接口备注
 *      description: 删除放映厅   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/theaters'
 *            example:
 *               _id: "60deb96e217ffc4d506ec8c2"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "成功"     # 返回 data
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/theaters'
 * */
router.delete('/delTheaters', async function (req, res, next) {
    const { _id } = req.body;
    const data = await theatersApi.delTheaters({ _id });
    res.send(data)
});


/**,
 * @swagger
 * /theaters/addTheaters:
 *    post:
 *      tags:
 *      - 放映厅          # 接口分类
 *      summary: 放映厅新增接口   # 接口备注
 *      description: 新增放映厅   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/theaters'
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "成功"     # 返回 data
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/theaters'
 * */
router.post('/addTheaters', async function (req, res, next) {
    const data = req.body;
    const datas = await theatersApi.addTheaters(data);
    res.send(datas)
});


/**,
 * @swagger
 * /theaters/patchTheaters:
 *    patch:
 *      tags:
 *      - 放映厅          # 接口分类
 *      summary: 放映厅修改接口   # 接口备注
 *      description: 修改放映厅   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/theaters'
 *            example:
 *              cinemasId: "60ddbca947e79918a490fdf9"
 *              name: "0厅"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "成功"     # 返回 data
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/theaters'
 * */
router.patch('/patchTheaters', async function (req, res, next) {
    const data = req.body;
    const datas = await theatersApi.patchTheaters(data);
    res.send(datas)
});

module.exports = router;
